/**
 * 
 */
package com.kstech.test.wqc.communication;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 负责与检验终端数据通讯
 *
 * @author zhaopuqing
 * @created 2016-10-19 下午6:05:26
 * @since v1.0
 */
public class CommunicationTask {

	private static ExecutorService task;

	/**
	 * 负责在通讯层收发数据
	 */
	private static CommunicationWorker worker;

	/**
	 * 开始执行通讯工作
	 */
	public static void start() {
		if (task == null) {
			task = Executors.newSingleThreadScheduledExecutor();
		}
		worker = new CommunicationWorker(Connection.getConnection());
		new Thread(worker).start();
	}

	/**
	 * 停止执行通讯工作
	 */
	public static void stop() {
		worker.stop();
		worker = null;
		Connection.getConnection().close();
	}

}
